package Observer.aboutjavautilobserve;

import Observer.Interfaces.DisplayElement;

import java.util.Observable;
import java.util.Observer;

/**
 * @version : 1.0
 * @author: pengzx
 * @Description:
 * @date: 11:07 2017/11/10
 */
public class NewCurrentConditionDIsplay implements Observer,DisplayElement {
    Observable observable;
    private float temperature;
    private float humidity;

    @Override
    public void display()
    {
        System.out.println("Current conditions: "+temperature+" F");
    }

    @Override
    public void update(Observable o, Object arg)
    {
        if (o instanceof WeatherData){
            WeatherData weatherData = (WeatherData) o;
            this.temperature = weatherData.getTemp();
            this.humidity = weatherData.getHumidity();
            display();
        }
    }

    public NewCurrentConditionDIsplay(Observable observable)
    {
        this.observable = observable;
        observable.addObserver(this);
    }
}
